package cn.com.dashihui.web.controller;

import java.util.List;

import com.jfinal.aop.Duang;
import com.jfinal.kit.StrKit;

import cn.com.dashihui.web.base.BaseController;
import cn.com.dashihui.web.dao.Seller;
import cn.com.dashihui.web.dao.SendSeller;
import cn.com.dashihui.web.service.SendSellerService;
public class SendSellerController extends BaseController{
	private SendSellerService sendSellerService = Duang.duang(SendSellerService.class);

		
		public void index(){
			int id = getCurrentUser().getInt("id");
			Seller seller = sendSellerService.findSeller(id);
			int sellerid = seller.getInt("id");
			List<SendSeller> listSendSeller = sendSellerService.findSendSeller(sellerid);
			setAttr("listSendSeller", listSendSeller);
	        render("index.jsp");
	   }
	 /**
	  * 添加公司
	  */
	  public void toAdd(){
		  render("add.jsp");
	  } 
	  /**
	   * 添加公司
	   */
	  public void doAdd(){
		 int id = getCurrentUser().getInt("id");
		 Seller seller = sendSellerService.findSeller(id);
		 int sellerid = seller.getInt("id");
		 String sendSellerName = getPara("sendSellerName");
		 SendSeller sendSeller = new SendSeller();
		 sendSeller.set("sendSellerName", sendSellerName).set("sellerid", sellerid);
		 sendSeller.save();
		 renderSuccess();
	  } 
	  /**
	  * 编辑
	  */
	  public void toEdit(){
		  int id = getParaToInt(0,0);
		  SendSeller sendSeller = sendSellerService.findById(id);
		  setAttr("sendSeller", sendSeller);
		  render("edit.jsp");
	  } 
	  /**
	   * 
	   */
	  public void doEdit(){
		  int id = getParaToInt("id", 0);
		  SendSeller sendSeller = sendSellerService.findById(id);
		  String sendSellerName = getPara("sendSellerName");
		  if (StrKit.isBlank(sendSellerName)) {
			renderResult(1);
			return;
		  }
		  sendSeller.set("sendSellerName", sendSellerName);
		  sendSeller.update();
		  renderSuccess();
	  } 
	/**
	 * 删除规格
	 */
	public void doDelete(){
		int id = getParaToInt(0,0);
		if(id!=0&&sendSellerService.delete(id)){
			renderSuccess();
			return;
		}
		renderFailed();
	}
}
